<template>
  <div>
    <div>
      <FormPanel ref="formPanel" :list="fromList" :cols="2" labelWidth="110" :isSubmitBtn="false"></FormPanel>
    </div>

    <div
      :style="{
        position: 'absolute',
        left: 0,
        bottom: 0,
        right: 0,
        zIndex: 9,
        borderTop: '1px solid #e9e9e9',
        padding: '10px 20px',
        background: '#fff',
        textAlign: 'right'
      }"
    >
      <AjaxButton type="primary" :disabled="newStatus" :click="saveDialog">保 存</AjaxButton>
      <!-- <AjaxButton type="primary" :disabled="submitEnable" :click="submit">提 报</AjaxButton> -->
      <el-button @click="closeDialog">关 闭</el-button>
    </div>
  </div>
</template>

<script>
// import FormPanel from '../../../../components/FormPanel/FormPanel.vue';
// import WorkSearch from './WorkSearch.vue';
// import { applyMileageChange } from '@/api/repair/repairBusiness/mileageModify/index.js';
import { queryModelProduct, addModelProduct } from '@/api/repair/repairBusiness/model/index.js';
import { getBrand, getSeries, getModel } from '@/api/customerRepair/customerCare/insuranceDueRemind/index';
import moment from 'moment';
import SERVER from '@/api/server';
import { getConfigHeaders } from '@/api/fetch';
import { jsonToHump } from '@/utils/index';
import axios from '@/api/fetch';
export default {
  props: ['row', 'type'],
  data() {
    return {
      fromList: this.createFromList(),
      modelId: undefined,
      isShowGdcx: false,
      fileList: [],
      getConfigHeaders: getConfigHeaders,
      ownerNo: '',
      newStatus: false
    };
  },
  computed: {
    submitEnable() {
      return !!!this.fromList.find(x => x.fieldName === 'changeNo').initialValue;
    }
  },
  mounted() {
    if (this.type == 'edit') {
      this.fromList.forEach(x => {
        x.initialValue = this.row[x.fieldName];
      });
      this.modelId = this.row.modelId;
    }
  },
  methods: {
    createFromList() {
      return [
        {
          type: 'INPUT',
          label: '车型代码',
          fieldName: 'MODEL_CODE',
          rules: [{ required: true, message: '请输入', trigger: 'blur' }]
        },
        {
          type: 'INPUT',
          label: '整编代码',
          fieldName: 'PRODUCT_CODE',
          disabled: true
        }
      ];
    },
    async saveDialog(type) {
      const [err, data] = await this.$refs.formPanel.GET_FORM_DATA();
      if (err) return;
      data.ownerNo = this.ownerNo;
      if (type === 'submit') {
        data.modelId = this.modelId;
        data.status = 99931002; // 提报
      } else {
        data.modelId = this.modelId;
        data.status = this.type === 'add' ? 99931001 : this.row.status; // 保存
      }
      console.log(this.fileList, 'this.fileList');
      if (this.fileList.length) {
        data.fileName = this.fileList[0].name;
        data.fileAddr = this.fileList[0].url;
      }
      let json = JSON.parse(JSON.stringify(data))
      jsonToHump(json);
      let res = await addModel(json);
      if (res.resultCode === 200) {
        if (type === 'submit') {
          this.$notify.success({ type: '提示信息', message: '提报成功!!' });
        } else {
          this.$notify.success({ type: '提示信息', message: '保存成功!!' });
          this.newStatus = true;
        }
        this.$emit('close');
      }
    },
    async getBrandAndSeries(){
      let brandRes = await getBrand();
      this.fromList.find(x=>x.fieldName=='BRAND_ID').itemList = brandRes.data.map(x => ({ text: x.BRAND_NAME, value: x.BRAND_ID }));
      let seriesRes = await getSeries();
      this.fromList.find(x=>x.fieldName=='SERIES_ID').itemList = seriesRes.data.map(x => ({ text: x.SERIES_NAME, value: x.SERIES_ID }));
    },
    // 提报
    submit() {
      this.saveDialog('submit'); //
    },
    closeDialog(param) {
      this.$emit('close');
    },

    confirmGdcx([param]) {
      this.isShowGdcx = false;
      this.fromList.find(x => x.fieldName === 'roNo').initialValue = param['RO_NO'];
      this.fromList.find(x => x.fieldName === 'vin').initialValue = param['VIN'];
      this.fromList.find(x => x.fieldName === 'license').initialValue = param['LICENSE'];
      this.fromList.find(x => x.fieldName === 'ownerName').initialValue = param['OWNER_NAME'];
      this.ownerNo = param['OWNER_NO'];
      this.fromList.find(x => x.fieldName === 'beforeMileage').initialValue = param['MILEAGE'];
    }
  }
};
</script>
